#encoding: utf-8
import os
from app import create_app, db, email
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand

# 获取环境变量
ENV = os.getenv("ENV") or "default"

# 实例化app
app = create_app(ENV)

# 实例化Manager
manager = Manager(app)

# 1. 要使用flask_migrate, 必须绑定app和db
migrate = Migrate(app, db)
# 2. 要MigrateCommand命令添加到manager中

manager.add_command("db", MigrateCommand)

# 模型 ---------> 迁移文件 ----------> 表
# 1. 在终端中初始化需要迁移的数据库: python manage.py db init
# 2. 在终端中需要将模型生成迁移文件: python manage.py db migrate
# 3. 从迁移文件映射到mysql数据库中: python manage.py db upgrade

@manager.command
def hello():
    print("hello world")

if __name__ == "__main__":
    manager.run()